Repository navigation
spacemit: fix MoE row-map capacity for repeated expert IDs - #99
Merged
alex-spacemit merged 1 commit intoDec 4, 2026
Merged
Conversation
Assisted-by: Codex
alex-spacemit
merged commit Dec 4, 2026
75b1485
into
spacemit-com:mtmd-backend
13 of 20 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and behavior
Correctness fix, not a new MoE compute optimization. MUL_MAT_ID may receive the same expert ID in several slots for one token. Sizing each expert's row map only to the token count allows repeated-slot entries to overwrite the next expert's map.
Size and index each expert's map for the full number of ID slots and move subsequent M4 scratch beyond the larger table. Each selected activation slot then retains its own output mapping.
Change and design
Only
ime.cppchanges: row-map workspace sizing, per-expert indexing and the following M4 scratch offset. The arithmetic kernels and the existing M8 tail-padding policy from #89 remain unchanged.Worst-case workspace increases in proportion to the number of selected slots. This supports the operator's repeated-ID input semantics; ordinary top-k routing need not generate duplicates for the bug to be valid.
Scope is limited to
ggml/src/ggml-spacemit/. Impact classification: execution-path change. No changes to the retired CPU backend, model code, public API or test sources. Local validation fixtures are excluded. This independently based module commit preserves the target branch's common MTP graph/rollback paths; experimental noMTP-wide reversions are not submitted. No new external dependency is added.Validation
Base:
mtmd-backendat3f5ce5fd84f4dc6e7e621642cfef0143d49e7c24. Candidate:797ff0fe303e55e1063f963a66676a6aa46ad5d3; source tree4c9f5d84895e5190139ee4277ae90ab6a38bb948.The exact submitted production source passed a RISC-V Release cross-build of
ggml-spacemitusing the SpacemiT v1.1.2 toolchain (GCC 14.3),cmake/riscv64-spacemit-linux-gnu-gcc.cmake,GGML_SPACEMIT=ON,GGML_RV_ZBA=ON,GGML_OPENMP=OFF, Spert 0.6.3 and SpacemiT ORT 2.0.6. Build target:cmake --build <build> --target ggml-spacemit --parallel 24. Backend DSO SHA-256:faa2032c0d053af501bb5d8f8e429f389ed8dd5e38c36d68adb431412e6d1da7. Source hashes were checked before/after the build and against the committed files.Reproduction: SPACEMIT0, Q4_0 weights with K=512, N=2048, 16 experts; one token, eight distinct F32 activation slots and IDs
[0,1,2,3,0,1,2,3]. Compare MUL_MAT_ID against an independent CPU reference using NMSE <= 5e-4.The original backend failed this input at NMSE 1.802669. The archived corrected K3-179 package passed 15/15 cases with the default schedule and 60/60 across four experimental schedules at the same threshold. Cases cover repeated IDs, all slots selecting one expert, unique IDs, one/two tokens and broadcast/nonbroadcast activations. Optional grouping/scheduling experiments are outside this PR.
Run labels:
mmid-duplicate-v18-repro-board179-r1andmmid-groups-v25-board179-r1. These are historical operator results for the same capacity fix, not fresh board execution of this independent PR head.git diff --check, UTF-8/LF and added-line whitespacePerformance
No throughput benefit is claimed. The change corrects workspace capacity and indexing; it increases worst-case scratch allocation. Final-head model correctness and a model-level performance comparison are NOT RUN. This PR does not reuse the performance numbers for #89's separate M8-padding change.
Risks and limits
Worst-case workspace is larger. Historical cases establish the duplicate-slot correction, not broad end-to-end model coverage or a throughput improvement. The final independent head needs target revalidation.
The historical module comparisons used the common noMTP experimental baseline on top of
3f5ce5fd; this PR instead preserves upstream common MTP behavior. Historical results are not claimed as new measurements of the final independent head. Raw build/test/benchmark archives are retained privately and are not publicly attached; the cases, results, artifact identities and limits above are the reviewable record here. Exact-input model replay is not provided by these summaries. Required final-head target evidence remains pending; this submission requests review, not a waiver or a claim of merge readiness. No maintainer exception has been granted. CI status is separate from the local results above.AI assistance and contributor responsibility
Codex assisted with source preparation, static review, local build/check execution, historical evidence analysis and this PR description. The contributor discussed the module design and explicitly requested publication. No unrecorded personal review, maintainer approval or target execution is asserted. The contributor remains responsible for reviewing the submitted code and claims and addressing review feedback.